package online.abor.springcloud.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.sun.org.apache.bcel.internal.generic.RETURN;
import online.abor.springcloud.entities.Dept;
import online.abor.springcloud.service.DeptService;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class DeptController {
    private final DeptService service;


    public DeptController(DeptService service) {
        this.service = service;
    }

    @HystrixCommand(fallbackMethod = "processHystrix_GET")
    @GetMapping(value = "/dept/get/{id}")
    public Dept get(@PathVariable("id") Long id) {
        Dept dept = service.get(id);
        if (dept==null)
            throw new RuntimeException("该ID("+id+")没有对应信息");
        return dept;
    }

    private Dept processHystrix_GET(@PathVariable("id") Long id) {
        return new Dept().setDeptno(id).setDname("该ID没有对应的信息,NULL ==>  @HystrixCommand").setDb_source("No This Database in Mysql");
    }

}
